// @before-stub-for-debug-begin
#include <vector>
#include <string>
#include "commoncppproblem198.h"

using namespace std;
// @before-stub-for-debug-end

/*
 * @lc app=leetcode.cn id=198 lang=cpp
 *
 * [198] 打家劫舍
 */

// @lc code=start
class Solution {
public:
    int rob(vector<int>& nums) {
        int n = nums.size();
        vector<int> dp(2);
        dp[1] = nums[0];
        
        for (int i = 1; i < n; ++i) {
            int tmp = dp[0];
            dp[0] = max(dp[0], dp[1]);
            dp[1] = tmp + nums[i];
        }

        return max(dp[0], dp[1]);

    }
};
// @lc code=end

